import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/net/internet_api.dart';
import 'package:xiongan_app_yy/pages/common/LoadBuilder.dart';
import 'package:xiongan_app_yy/provider/automounting_provider.dart';
import 'package:xiongan_app_yy/utils/toast_utils.dart';
import 'package:xiongan_app_yy/widgets/into_warehousing_item.dart';
import 'package:xiongan_app_yy/widgets/search_widget.dart';

import 'executivesampling.dart';

class ExecutivesamplingSearchPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return ExecutivesamplingSearchPageState();
  }
}

class ExecutivesamplingSearchPageState extends State<ExecutivesamplingSearchPage>{
  int size=0;
  List<dynamic> data;
  @override
  Widget build(BuildContext context) {
    return SearchWidget(tipsText: "请输入检测任务号",onTapFuns: (value){
      if(value!=null&&value.toString().length>0){
        onSearch(value);
      }else{
        TostUtil.showToast("请输入检测任务号");
      }

    },child: LoadBuilder(
    visibility: false,
    emptyVisibility: size == 0,
    emptyTextVisibility: size == 0,
    textEmptyTips: "暂无内容",
    builder: ListView.separated(
        itemBuilder: (BuildContext context, int index) {
          return TextCartItem(
            data: data,
            index: index,
            onTapFuns: (int index) {
              Navigator.of(context)
                  .pushNamed("/executivesampling_list",arguments: data[index]["id"]).then((data){
                if(data=="back"){

                }
              });
            },
          );
        },
        separatorBuilder: (BuildContext context, int index) =>
            Divider(height: 1, color: Colors.transparent),
        itemCount: size)),
    );
  }

  void onSearch(String str) {
    InternetAPI.getInstance().get(
      "WTesting/DescSpotcheckTask/GetAllDescSpotcheckTask",
          (value) {
        print(value.toString());
        setState(() {
          data=value;
          size=data.length;
        });
      },
      params: {
        "operaterUserName": DataSingleton().Data.username,
        "operaterUserId": DataSingleton().Data.id,
        "tenantId": DataSingleton().Data.tenantId,
        "pageno": 1,
        "pageSize": -1,
        "taskno":str
      },
    );

  }
}